package com.md.client;

import com.md.api.OpenUsersApi;
import com.md.client.helper.DefaultOpenUsersController;
import com.md.request.open.CheckPermissionRequest;
import com.md.request.open.QueryUsersRequest;
import com.md.response.UsersResponse;
import com.md.util.SpringContextUtil;
import lombok.experimental.UtilityClass;

/**
 * @author 刘骄阳
 * 2024-07-14 22:37
 */
@UtilityClass
public class OpenUsersClient {

  private OpenUsersApi openUsersApi;

  private static OpenUsersApi getOpenSystemApi() {
    if (openUsersApi == null) {
      openUsersApi = SpringContextUtil.getBean(DefaultOpenUsersController.class);
    }
    return openUsersApi;
  }

  public static UsersResponse queryUserInfo(final Long id) {
    QueryUsersRequest request = new QueryUsersRequest();
    request.setId(id);
    return getOpenSystemApi().queryUserInfo(request).getData();
  }

  public static Boolean checkPermission(final Long userId, final Long apiId) {
    CheckPermissionRequest request = new CheckPermissionRequest();
    request.setApiId(apiId);
    request.setUserId(userId);
    return getOpenSystemApi().checkPermission(request).getData();
  }

}
